﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using YiCreateWebApp.DBConnect;

namespace YiCreateWebApp.User
{
    public partial class Login_div : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }



        protected void btnmLogin_Click(object sender, EventArgs e)
        {
            //实例化公共类对象
            DB db = new DB();
            string userName = this.txtUserName.Text.Trim();
            string password = db.GetMD5(this.txtPwd.Text.Trim());
            string num = this.txtValidateNum.Text.Trim();
            if (Session["ValidateNum"].ToString() == num.ToUpper())
            {
                //获取用户信息
                SqlDataReader dr = db.reDr("select * from tb_User where UserName = '" + userName + "' and PassWord = '" + password + "'");
                dr.Read();
                if (dr.HasRows)  //通过dr中是否包含行判断用户是否通过身份验证
                {
                    Session["UserID"] = dr.GetValue(0); //将该用户的ID存入Session["UserId"]中
                    Session["Role"] = dr.GetValue(4); //将改用户的权限存入Session["Role"]中
                    Response.Redirect("~/User/UserManagement.aspx");    //跳转到主页
                }
                else
                {
                    Response.Write("<script>alert('I am sorry,登陆失败！请重新输入');location='Login.aspx'</script>");
                }
                dr.Close();
            }
            else
            {
                Response.Write("<script>alert('亲,验证码输错了');location='Login.aspx'</script>");
            }
        }

        protected void btnmRegister_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/User/Register.aspx");    //跳转到用户注册页面
        }
    }
}